#include <gflags/gflags.h>

#include "mysql.hpp"
#include "mysql_chat_session_member.hpp"


DEFINE_bool(run_mode, true, "是否为调试模式");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，用于指定日志输出等级");

void append_test(im::ChatSessionMemberTable &tb) {
    im::ChatSessionMember csm1("会话ID1", "用户ID1");
    tb.append(csm1);
    im::ChatSessionMember csm2("会话ID1", "用户ID2");
    tb.append(csm2);
    im::ChatSessionMember csm3("会话ID2", "用户ID3");
    tb.append(csm3);
}

void multi_append_test(im::ChatSessionMemberTable &tb) {
    im::ChatSessionMember csm1("会话ID3", "用户ID1");
    im::ChatSessionMember csm2("会话ID3", "用户ID2");
    im::ChatSessionMember csm3("会话ID3", "用户ID3");
    std::vector<im::ChatSessionMember> list = {csm1, csm2, csm3};
    tb.append(list);
}

void remove_test(im::ChatSessionMemberTable &tb) {
    im::ChatSessionMember csm3("会话ID2", "用户ID3");
    tb.remove(csm3);
}

void ss_members(im::ChatSessionMemberTable &tb) {
    auto res = tb.members("会话ID1");
    for (auto &id : res) {
        std::cout << id << std::endl;
    }
}
void remove_all(im::ChatSessionMemberTable &tb) {
    tb.remove("会话ID3");
}

int main(int argc, char *argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    im::initLogger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    auto db = im::ODBFactory::create("root", "123456", "127.0.0.1", "im", "utf8", 0, 1);

    im::ChatSessionMemberTable tb(db);
    append_test(tb);
    multi_append_test(tb);
    remove_test(tb);
    ss_members(tb);
    remove_all(tb);

    return 0;
}